<template>
  <view class="shop-item" @click="navigateToShop">
    <!-- 店铺标志 -->
    <image class="shop-logo" :src="shop.logo || '/static/images/default-shop.png'" mode="aspectFill"></image>
    
    <view class="shop-info">
      <!-- 店铺名称 -->
      <view class="shop-name">{{ shop.name }}</view>
      
      <!-- 店铺评分与总销量 -->
      <view class="shop-rating-sales">
        <view class="rating">
          <uni-icons type="star-filled" size="14" color="#ff9500"></uni-icons>
          <text>{{ shop.rating || '0.0' }}</text>
        </view>
        <text class="sales">月销 {{ formatNumber(shop.monthlySales || 0) }}</text>
      </view>
      
      <!-- 店铺分类和配送信息 -->
      <view class="shop-meta">
        <text class="category">{{ shop.categoryName || '未分类' }}</text>
        <text class="delivery" v-if="shop.deliveryTime">{{ shop.deliveryTime }}分钟送达</text>
        <text class="distance" v-if="shop.distance">{{ formatDistance(shop.distance) }}</text>
      </view>
      
      <!-- 店铺活动信息 -->
      <view class="shop-promotion" v-if="shop.promotions && shop.promotions.length > 0">
        <text class="promotion-tag">活动</text>
        <text class="promotion-text">{{ shop.promotions[0].description }}</text>
      </view>
    </view>
    
    <!-- 进入店铺按钮 -->
    <view class="enter-shop">
      <button class="btn-enter" size="mini" type="default">进店</button>
    </view>
  </view>
</template>

<script>
export default {
  props: {
    shop: {
      type: Object,
      default: () => ({})
    }
  },
  
  methods: {
    navigateToShop() {
      if (!this.shop.id) {
        uni.showToast({
          title: '店铺信息不完整',
          icon: 'none'
        });
        return;
      }
      
      uni.navigateTo({
        url: `/pages/shop/detail?id=${this.shop.id}`
      });
    },
    
    formatNumber(num) {
      if (num >= 10000) {
        return (num / 10000).toFixed(1) + '万';
      }
      return num.toString();
    },
    
    formatDistance(distance) {
      if (distance < 1000) {
        return distance + 'm';
      } else {
        return (distance / 1000).toFixed(1) + 'km';
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.shop-item {
  display: flex;
  padding: 24rpx;
  background-color: #ffffff;
  margin-bottom: 16rpx;
  border-radius: 12rpx;
}

.shop-logo {
  width: 120rpx;
  height: 120rpx;
  border-radius: 8rpx;
  margin-right: 20rpx;
  flex-shrink: 0;
}

.shop-info {
  flex: 1;
  overflow: hidden;
}

.shop-name {
  font-size: 30rpx;
  font-weight: bold;
  color: #333333;
  margin-bottom: 12rpx;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.shop-rating-sales {
  display: flex;
  align-items: center;
  margin-bottom: 12rpx;
  font-size: 24rpx;
  
  .rating {
    display: flex;
    align-items: center;
    margin-right: 16rpx;
    color: #ff9500;
    
    text {
      margin-left: 4rpx;
    }
  }
  
  .sales {
    color: #666666;
  }
}

.shop-meta {
  display: flex;
  align-items: center;
  margin-bottom: 12rpx;
  font-size: 22rpx;
  color: #999999;
  
  .category {
    background-color: #f5f5f5;
    padding: 6rpx 12rpx;
    border-radius: 4rpx;
    margin-right: 12rpx;
  }
  
  .delivery, .distance {
    margin-right: 12rpx;
  }
}

.shop-promotion {
  display: flex;
  align-items: center;
  font-size: 22rpx;
  
  .promotion-tag {
    padding: 4rpx 8rpx;
    background-color: #fff1f0;
    color: #ff5500;
    border-radius: 4rpx;
    margin-right: 8rpx;
  }
  
  .promotion-text {
    color: #666666;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

.enter-shop {
  display: flex;
  align-items: center;
  margin-left: 16rpx;
  
  .btn-enter {
    padding: 8rpx 24rpx;
    background-color: #ffffff;
    color: #ff5500;
    border: 1px solid #ff5500;
    border-radius: 24rpx;
    font-size: 24rpx;
    line-height: 1.5;
  }
}
</style> 